package com.xiaolin.springbootdemo.utils;

import lombok.Data;

/**
 * @ClassName ResponseResult
 * @Description 响应模型数据
 * @Detail detail
 * @Author MyPC
 * @Date 2021/1/10
 * @Version 1.0
 */
@Data
public class ResponseResult<T> {

    private long statusCode;
    private String msg;
    private T date;

    protected ResponseResult(){

    }

    protected ResponseResult(long statusCode,String msg,T date){
        this.statusCode=statusCode;
        this.msg=msg;
        this.date=date;
    }

    /**
     * 默认成功响应
     * @return
     */
    public static <T> ResponseResult<T> success(T date){
        return new ResponseResult<>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMsg(),date);
    }

    /**
     * 自定义响应成功信息
     * @param date
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(T date,String msg){
        return new ResponseResult<>(ResultCode.SUCCESS.getCode(),msg,date);
    }

    /**
     * 错误响应信息
     * @param iCommonCode
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(ICommonCode iCommonCode){
        return new ResponseResult<>(iCommonCode.getCode(),iCommonCode.getMsg(),null);
    }

    /**
     * 错误响应信息
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> error(String msg){
        return new ResponseResult<>(ResultCode.FAILED.getCode(),msg,null);
    }

}
